#include <coap2/coap.h>

#include "coap-resource.h"
#include "coap-server-implement.h"

#  define NI_MAXHOST      1025
#  define NI_MAXSERV      32


void message_deal(char** data)
{
    printf("my data:%s\n", *data);

    const char *p = obtain_coap_message();
    printf("my data2: %s\n", p);

    free(p); /* must free */

    return ;
}


int main ()
{
    // coap_dtls_set_log_level(log_level);
    coap_log_t log_level = LOG_INFO;
    coap_set_log_level(log_level);

    char* data = NULL;
    register_message_handler = message_deal;
    

    int16_t ret = init_server_resource();

    if (ret != 0) {
        
        return -1;
    }

    char addr_str[NI_MAXHOST] = "::";
    char port_str[NI_MAXSERV] = "5683";

    ret = bind_server_addr(addr_str, port_str);
     if (ret != 0) {
        
        return -1;
    }

 
    server_event_loop();



    // coap_log_t log_level = LOG_INFO;

    // coap_context_t *ctx = create_context();
    // if (!ctx) return -1;

    // char addr_str[NI_MAXHOST] = "::";
    // char port_str[NI_MAXSERV] = "5683";

    // coap_startup();
    // coap_dtls_set_log_level(log_level);
    // coap_set_log_level(log_level);

    // bind_server_addr(addr_str, port_str, ctx);
    // init_resources(ctx);
    // event_loop(ctx);

    return 0;
}

